package edu.controller.admin;

import edu.dto.CountDto;
import edu.service.GoodsService;
import edu.service.OrdersService;
import edu.service.UserService;
import edu.support.base.controller.AdminBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@RequestMapping("admin/count")
@Controller
public class CountAdminController extends AdminBaseController {

    @Autowired
    private UserService userService;
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private OrdersService ordersService;

    /**
     * 统计首页
     *
     * @return
     */
    @RequestMapping({"index"})
    public String index(Model model) {
        List<CountDto> goodsData = goodsService.countByCategory();

        // 上午  销量排行榜
        List<CountDto> amData = ordersService.countByTime("AM");

        // 下午  销量排行榜
        List<CountDto> pmData = ordersService.countByTime("PM");


        model.addAttribute("goodsData", goodsData);
        model.addAttribute("amData", amData);
        model.addAttribute("pmData", pmData);
        return "admin/count/index";
    }

}
